/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');

window.Vue = require('vue');
import VueRouter from 'vue-router';

Vue.use(VueRouter);
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import '../theme/index.css';

Vue.use(ElementUI);
import axios from 'axios'

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

// Vue.component('layout-edit', require('./components/LayoutEditNew.vue'));


// axios.defaults.baseURL = 'https://www.easy-mock.com/mock/5aea77509d0dc53dc5af4c1d/dspt/api/'
// axios.defaults.baseURL = 'https://dspt.zkong.me/api/'
const {
  origin
} = window.location
axios.defaults.baseURL = `${origin}/api/`
// const { origin, port } = window.location
// axios.defaults.baseURL = `${origin}${port?`:${port}`:''}/api/`
// axios.defaults.baseURL = 'http://localhost:8888/api/'
axios.defaults.withCredentials = true

Vue.mixin({
  methods: {
    //日期转化字符串
    dateFormat(date, fmt = 'YYYY-MM-DD HH:mm:ss') {
      console.log('日期', date)
      if (/(Y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, `${date.getFullYear()}`.substr(4 - RegExp.$1.length));
      }

      const o = [{
          regex: 'M+',
          value: date.getMonth() + 1
        },
        {
          regex: 'D+',
          value: date.getDate()
        },
        {
          regex: 'h+',
          value: date.getHours() % 12 === 0 ? 12 : date.getHours() % 12
        },
        {
          regex: 'H+',
          value: date.getHours()
        },
        {
          regex: 'm+',
          value: date.getMinutes()
        },
        {
          regex: 's+',
          value: date.getSeconds()
        },
        {
          regex: 'q+',
          value: Math.floor((date.getMonth() + 3) / 3)
        },
        {
          regex: 'S',
          value: date.getMilliseconds()
        }
      ];
      o.forEach(item => {
        if (new RegExp(`(${item.regex})`).test(fmt)) {
          fmt = fmt.replace(
            RegExp.$1,
            RegExp.$1.length === 1 ? item.value : `00${item.value}`.substr(`${item.value}`.length)
          );
        }
      });

      return fmt;
    }
  }
})

// const app = new Vue({
//   el: '#app'
// });
const mountList = {
  statistics: '/admin',
  categoryList: '/admin/categories',
  goodsList: '/admin/goods',
  storeList: '/admin/configs',
  bonusesTable: '/admin/bonuses/statistics',
  customersTable: '/admin/users',
  usersList: '/admin/users/list',
  integralLogs: '/admin/integralLogs',
  layoutTable: '/admin/layouts/setting',
  ordersTable: '/admin/orders',
  legalOrder: '/admin/returnLogs',
  evaluation: '/admin/goodsEvaluates',
  assetsTable: '/admin/assets',
  orderBook: '/admin/orderBook',
  flowWater: '/admin/categoryStatistics',
  setting: '/admin/setting'
}

// const { pathname} = window.location;

//概况
import StatisticsTable from './pages/statistics/Statistics'
// 商品分类
import CategoryList from './pages/categories/CategoryTable'
import CategoryAdd from './pages/categories/CategoryAdd'
import CategoryEdit from './pages/categories/CategoryEdit'
import GoodsList from './pages/categories/GoodsList'
// 商品
import GoodAdd from './pages/good/GoodAdd'
import GoodEdit from './pages/good/GoodEdit'
import GoodEditSome from './pages/good/GoodEditSome'
import GoodList from './pages/good/GoodTable'
// 店铺概况
import StoreList from './pages/storeProfile/StoreTable'
// 优惠券
import BonusesTable from './pages/bonuses/BonusesTable'
import BonusesAdd from './pages/bonuses/BonusesAdd'
import BonusesEdit from './pages/bonuses/BonusesEdit'
import BonusesUserList from './pages/bonuses/bonusesUserList'
//客户管理
import CustomersTable from './pages/customers/CustomersTable'
import CustomerDetails from './pages/customers/CustomerDetails'
//积分管理
import IntegralTable from './pages/IntegralLogs/IntegralTable'
//订单管理
import OrdersTable from './pages/orders/OrdersTable'
import LegalOrder from './pages/orders/LegalOrder'
import Evaluation from './pages/orders/Evaluation'
//用户管理
// import UsersList from './pages/users/UsersList'
// import UsersConfig from './pages/users/UsersConfig'
// import UsersEdit from './pages/users/UsersEdit'
// import UsersOrder from './pages/users/UsersOrder'
//资产管理
import AssetsTable from './pages/assets/Assets'
import OrderBook from './pages/OrderBook/OrderBook'
import FlowWater from './pages/property/FlowWater'
import BillSummary from './pages/property/BillSummary'
import OrderDetails from './pages/OrderBook/OrderDetails'
// 店铺装修
// import LayoutDesign from './pages/layout/LayoutDesign'
import LayoutTable from './pages/layout/LayoutTable'

const {
  location: {
    pathname
  }
} = window

const pathList = {
  LayoutDesign: '/admin/layouts/setting'
}

// if (pathname === pathList.LayoutDesign) {
//     const layoutDesign = new Vue({
//         el: '#layout-design',
//         render: h => h(LayoutDesign)
//     })
// }

if (pathname === mountList.layoutTable) {
  const layoutTable = new Vue({
    el: '#layout-table',
    render: h => h(LayoutTable)
  })
}

if (pathname === mountList.categoryList) {
  const categoryRouter = new VueRouter({
    routes: [{
        path: '/',
        component: CategoryList,
        name: 'CategoryList'
      },
      {
        path: '/add',
        component: CategoryAdd,
        name: 'CategoryAdd'
      },
      {
        path: '/edit',
        component: CategoryEdit,
        name: 'CategoryEdit'
      },
      {
        path: '/list',
        component: GoodsList,
        name: 'GoodsList'
      },

    ]
  });
  const categoryTable = new Vue({
    router: categoryRouter
  }).$mount('#categories-table');
}

if (pathname === mountList.goodsList) {
  const goodRouter = new VueRouter({
    routes: [{
        path: '/',
        component: GoodList,
        name: 'GoodList'
      },
      {
        path: '/add',
        component: GoodAdd,
        name: 'GoodAdd'
      },
      {
        path: '/edit',
        component: GoodEdit,
        name: 'GoodEdit'
      }
    ]
  });
  const goodTable = new Vue({
    router: goodRouter
  }).$mount('#good-table');
}

if (pathname === mountList.storeList) {
  const storeRouter = new VueRouter({
    routes: [{
        path: '/',
        component: StoreList,
        name: 'StoreList'
      },
      // { path: '/add', component: StoreAdd, name: 'StoreAdd' },
      // { path: '/edit', component: StoreEdit, name: 'StoreEdit' }
    ]
  });
  const storeTable = new Vue({
    router: storeRouter
  }).$mount('#store-table');
}

if (pathname === mountList.bonusesTable) {
  const bonusesRouter = new VueRouter({
    routes: [{
        path: '/',
        component: BonusesTable,
        name: 'BonusesTable'
      },
      {
        path: '/add',
        component: BonusesAdd,
        name: 'BonusesAdd'
      },
      {
        path: '/edit',
        component: BonusesEdit,
        name: 'BonusesEdit'
      },
      {
        path: '/list',
        component: BonusesUserList,
        name: 'BonusesUserList'
      },
    ]
  });
  const bonusesTable = new Vue({
    router: bonusesRouter
  }).$mount('#bonuses-table');
}

if (pathname === mountList.customersTable) {
  const CustomersRouter = new VueRouter({
    routes: [{
        path: '/',
        component: CustomersTable,
        name: 'CustomersTable'
      },
      {
        path: '/details',
        component: CustomerDetails,
        name: 'CustomerDetails'
      },
    ]
  });
  const customersTable = new Vue({
    router: CustomersRouter
  }).$mount('#customers-table');
}

if (pathname === mountList.assetsTable) {
  const assetsRouter = new VueRouter({
    routes: [{
      path: '/',
      component: AssetsTable,
      name: 'AssetsTable'
    }]
  });
  const assetsTable = new Vue({
    router: assetsRouter
  }).$mount('#assets-table');
}

if (pathname === mountList.orderBook) {
  const OrderBookRouter = new VueRouter({
    routes: [{
        path: '/',
        component: OrderBook,
        name: 'OrderBook'
      },
      {
        path: '/details',
        component: OrderDetails,
        name: 'OrderDetails'
      }
    ]
  });
  const orderBook = new Vue({
    router: OrderBookRouter
  }).$mount('#order-book');
}

if (pathname === mountList.flowWater) {
  const flowWaterRouter = new VueRouter({
    routes: [{
        path: '/',
        component: FlowWater,
        name: 'FlowWater'
      },
      {
        path: '/summary',
        component: BillSummary,
        name: 'BillSummary'
      }
    ]
  });
  const flowWater = new Vue({
    router: flowWaterRouter
  }).$mount('#flow-water');
}

if (pathname === mountList.ordersTable) {
  const ordersTable = new Vue({
    el: '#orders-table',
    render: h => h(OrdersTable)
  })
}

if (pathname === mountList.legalOrder) {
  const legalOrder = new Vue({
    el: '#legal-order',
    render: h => h(LegalOrder)
  })
}

if (pathname === mountList.evaluation) {
  const evaluation = new Vue({
    el: '#evaluation',
    render: h => h(Evaluation)
  })
}

// if(pathname === mountList.usersList){
//     const UsersRouter = new VueRouter({
//        routes:[
//            {path:'/', component:UsersList, name:'UsersList'},
//            {path:'/config', component:UsersConfig, name:'UsersConfig'},
//            {path:'/edit', component:UsersEdit, name:'UsersEdit'},
//            {path:'/order', component:UsersOrder, name:'UsersOrder'}
//        ]
//     });
//     const usersList = new Vue({
//         router: UsersRouter
//     }).$mount('#users-list');
// }

if (pathname === mountList.usersList) {
  const UsersRouter = new VueRouter({
    routes: [{
        path: '/',
        component: UsersList,
        name: 'UsersList'
      },
      {
        path: '/config',
        component: UsersConfig,
        name: 'UsersConfig'
      },
      {
        path: '/edit',
        component: UsersEdit,
        name: 'UsersEdit'
      },
      {
        path: '/order',
        component: UsersOrder,
        name: 'UsersOrder'
      }
    ]
  });
  const usersList = new Vue({
    router: UsersRouter
  }).$mount('#users-list');
}

if (pathname === mountList.statistics) {
  const statisticsTable = new Vue({
    el: '#statistics-table',
    render: h => h(StatisticsTable)
  })
}

if (pathname === mountList.integralLogs) {
  const integralTable = new Vue({
    el: '#integral-table',
    render: h => h(IntegralTable)
  })
}

import Setting from './pages/setting/Setting.vue'
import Authentication from './pages/setting/children/Authentication.vue'
import Freight from './pages/setting/children/Freight.vue'
import FreightEdit from './pages/setting/FreightEdit.vue'
import MemberInfo from './pages/setting/children/MemberInfo.vue'
import ShopInfo from './pages/setting/children/ShopInfo.vue'
import Withdraw from './pages/setting/children/Withdraw.vue'
import PasswordChange from './pages/setting/children/PasswordChange'

if (pathname === mountList.setting) {
  const SettingRouter = new VueRouter({
    routes: [{
      path: '/',
      component: Setting,
      children: [{
          path: '/',
          component: MemberInfo,
          name: 'MemberInfo'
        },
        {
          path: '/password',
          component: PasswordChange,
          name: 'PasswordChange'
        },
        {
          path: '/authentication',
          component: Authentication,
          name: 'Authentication'
        },
        {
          path: '/freight',
          component: Freight,
          name: 'Freight'
        },
        {
          path: '/shopinfo',
          component: ShopInfo,
          name: 'ShopInfo'
        },
        {
          path: '/withdraw',
          component: Withdraw,
          name: 'Withdraw'
        }
      ]
    }, {
      path: '/freightedit',
      component: FreightEdit,
      name: 'FreightEdit'
    }]
  });
  const setting = new Vue({
    router: SettingRouter
  }).$mount('#setting');
}